### Key constraint details

Primary keys are automatically inferred for [`Kafka sources`](/sql/create-source/kafka)
using [`Upsert`](/sql/create-source/kafka/#handling-upserts) or
[`Debezium`](/sql/create-source/kafka/#using-debezium) envelopes and
[`Postgres sources`](/sql/create-source/postgres).

For other source configurations, the [`key_constraint`](#key_constraint) syntax
allows to *manually* declare a set of columns as a primary key. This enables
optimizations and constructs that rely on a key to be present when it cannot be
inferred.

<strong>WARNING!</strong> Materialize will *not enforce* the constraint and
will produce wrong results if it is not correct.
